// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   ConfigReader.java

package include.auto_execute;

import java.io.File;
import java.util.Iterator;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;

// Referenced classes of package include.auto_execute:
//			Path

public class ConfigReader extends Path
{

	private String file;
	private SAXBuilder builder;
	private Document doc;
	private Element root;
	private int length;
	private String classNames[];
	private String methods[];

	public ConfigReader()
	{
		file = "";
		builder = null;
		doc = null;
		root = null;
		length = 0;
		classNames = null;
		methods = null;
		file = (new StringBuilder(String.valueOf(getPath()))).append("/conf/auto.xml").toString();
		try
		{
			builder = new SAXBuilder("org.apache.xerces.parsers.SAXParser");
			doc = builder.build(new File(file));
			root = doc.getRootElement();
		}
		catch (Exception je)
		{
			je.printStackTrace();
		}
		setLength();
	}

	private void setLength()
	{
		int length = 0;
		List tasks = root.getChildren("task");
		for (Iterator it = tasks.iterator(); it.hasNext(); it.next())
			length++;

		this.length = length;
	}

	private int getLength()
	{
		return length;
	}

	public String[] getClassNames()
	{
		if (classNames != null)
			return classNames;
		String result[] = new String[length];
		List tasks = root.getChildren("task");
		Iterator it = tasks.iterator();
		for (int index = 0; it.hasNext(); index++)
		{
			Element task = (Element)it.next();
			result[index] = task.getChild("classname").getText();
		}

		classNames = result;
		return result;
	}

	public String[] getMethods()
	{
		if (methods != null)
			return methods;
		String result[] = new String[length];
		List tasks = root.getChildren("task");
		Iterator it = tasks.iterator();
		for (int index = 0; it.hasNext(); index++)
		{
			Element task = (Element)it.next();
			result[index] = task.getChild("method").getText();
		}

		methods = result;
		return result;
	}

	public String getMethod(String className)
	{
		if (classNames == null || methods == null)
		{
			classNames = getClassNames();
			methods = getMethods();
		}
		int index = indexOf(classNames, className);
		if (index == -1)
			return null;
		if (index >= methods.length)
			return null;
		else
			return methods[index];
	}

	private int indexOf(String array[], String element)
	{
		for (int i = 0; i < array.length; i++)
			if (array[i].equals(element))
				return i;

		return -1;
	}

	public static void main(String args[])
	{
		String names[] = (new ConfigReader()).getClassNames();
		if (names != null)
		{
			for (int i = 0; i < names.length; i++);
		}
	}
}
